
#ifndef __DSA_PRIVATE_KEY_H
#define __DSA_PRIVATE_KEY_H

#include "PrivateKey.h"
#include "DecryptionKey.h"
#include "SigningKey.h"
#include <openssl/dsa.h>
#include "../iface/SSLInterface.h"

/** An class encapsulating an DSA private key. */
class DSAPrivateKey : public PrivateKey, public SigningKey
{
   public:
      DSAPrivateKey();
      DSAPrivateKey(const char *name);
      // Construct a duplicate of the private key
      DSAPrivateKey(const DSAPrivateKey &other);
      // Construct from PEM format
      DSAPrivateKey(const char *pemtext, const char *name);
      // Construct from encrypted PEM format
      DSAPrivateKey(const char *pemtext, const char *password, const char *name);
      // Construct from OpenSSL format
      DSAPrivateKey(DSA *prvkey, const char *name);
      // Assignment constructor
      DSAPrivateKey &operator=(const DSAPrivateKey &other);
      // Destroy DSA private key
      ~DSAPrivateKey();
      // Get context
      int getCryptlibContext(CRYPT_CONTEXT *keycontext);
      // Get Signing context
      int getCryptlibSigningContext(CRYPT_CONTEXT *keycontext);
      // Get key components
      int getCryptlibKeyComponents(CRYPT_PKCINFO_DLP *dsakey);
      // Get new OpenSSL DSA object
      int getSSLKeyComponents(DSA **prvkey);
      // Get PEM data
      int getPEMKeyData(char **pemtext);
      // Get encrypted PEM data
      int getPEMKeyData(char **pemtext, const char *password);
      // Compare key to key
      int compareKeyBelongs(PublicKey *pubkey);
      // Get key type name
      int getKeyType() { return KEY_TYPE_PRIVATE_DSA; }
      // To import from text - Base64 RAW or PEM
      int importKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int exportKeyToASCII(char **text);
      // Import from text with password
      int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int exportKeyToASCIIWithPassword(char **text, const char *password);
   private:
      // Copy SSL type public keys
      static int copyDSASSLPrivateKey(DSA *dst, DSA *src);
      // Import private key (with optional password if it's encrypted)
      int importPrivateKeyWithOptionalPassword(const char *pemtext, const char *password);
      /** A pointer to the real DSA private key, held in SSL format. */
      DSA *key;
};

#endif
